using System;
using Anvil.Core;

namespace Anvil.Core.Commands
{
	/// <summary>
	/// Confirm that a field does not exceed a certain length.
	/// </summary>
	public class BaseLength : BaseLogic
	{
		public override bool RequestExecute(IRequestContext context)
		{
			string key = context[Tokens.KEY] as string;
			string target = context[key] as string;
			if (target == null) return CONTINUE;

			string val = context["value"] as string;
			int length = Convert.ToInt32(val);
			bool okay = target.Length <= length;
			if (!okay)
			{
				context.AddAlertForField(key);
			}

			return CONTINUE;
		}
	}
}